package model

import (
	"gorm.io/gorm"
	"time"
	"wechat_1004/global"
)

type Moment struct {
	Id           int32          `gorm:"column:id;type:int;comment:ID;primaryKey;not null;" json:"id"`                     // ID
	UserId       int32          `gorm:"column:user_id;type:int;comment:用户ID;not null;" json:"user_id"`                    // 用户ID
	Title        string         `gorm:"column:title;type:varchar(30);comment:标题;not null;" json:"title"`                  // 标题
	ContentImage string         `gorm:"column:content_image;type:varchar(300);comment:图片;not null;" json:"content_image"` // 图片
	ContentText  string         `gorm:"column:content_text;type:varchar(300);comment:文本;not null;" json:"content_text"`   // 文本
	CreatedAt    time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt    time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt    gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (m *Moment) TableName() string {
	return "moment"
}

// 发布动态
func (m *Moment) AddMoment() error {
	return global.DB.Create(&m).Error
}

// 查看
func (m *Moment) FindMoment() (list []Message, err error) {
	err = global.DB.Where("user_id = ?", m.UserId).Find(&list).Error
	return
}
